package com.sss.hloster06;

import java.util.Scanner;

public class JavaExercise35 {

	public static void main(String[] args) {
		test35();
	}

	/**
	 ** 输入数组，最大的与第一个元素交换，最小的与最后一个元素交换，输出数组
	 */
	private static void test35() {
		int n = 8;
		int[] arr = new int[n];
		Scanner sc = new Scanner(System.in);
		int index01 = 0, index02 = 0;
		System.out.println("请输入8个整数：");
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		System.out.println("您输入的数组为：");
		for (int i = 0; i < n; i++) {
			System.out.println(arr[i] + " ");
		}
		int max = arr[0], min = arr[0];
		for (int i = 0; i < n; i++) {
			if (arr[i] > max) {
				max = arr[i];
				index01 = i;
			}
			if (arr[i] < min) {
				min = arr[i];
				index02 = i;
			}
		}
		if (index01 != 0) {
			int temp = arr[0];
			arr[0] = arr[index01];
			arr[index01] = temp;
		}
		if (index02 != 0) {
			int temp = arr[n - 1];
			arr[n - 1] = arr[index02];
			arr[index02] = temp;
		}
		System.out.println("交换后的数组为：");
		for (int i = 0; i < n; i++) {
			System.out.print(arr[i] + " ");
		}
	}
}
